#pragma once
#ifndef __SWIG__

#include <D3DX11tex.h>
#else
#include "D3D11_swig.h"

#endif 
#include "CDXResource.h"


#ifdef __SWIG__
%include <typemaps.i>
%include "mui_typemap.i"
%apply SWIGTYPE* OUTPUT {D3D11_TEXTURE2D_DESC* pOutDesc};
%apply UINT* OUTPUT {UINT* width, UINT* height}; // GetFrameSize
%apply Handle* OUTPUT {HDC* outHDC}; // GetDC
%apply SWIGTYPE** OUTPUT { ID3D11UnorderedAccessView** ppUnorderAccessView};
%apply SWIGTYPE** OUTPUT { ID3D11ShaderResourceView** ppShaderResourceView};
%apply SWIGTYPE** OUTPUT { ID3D11RenderTargetView** ppRenderTargetView};
#endif


class CDXTexture2D : public CDXResource
{
protected:
	virtual HRESULT ReleaseResources();

protected:
	ID3D11Texture2D* m_pTexture;
private:
	ID3D11Texture2D* m_pReadAgentTexture;
	ID3D11Texture2D* m_pWriteAgentTexture;
public:
	CDXTexture2D(CDXDevice* pDevice);
	virtual ~CDXTexture2D();
	virtual HRESULT GetDC(BOOL discard, HDC* outHDC);
	virtual HRESULT ReleaseDC(RECT* pDirtyRect);
	virtual ID3D11Texture2D* GetD3D11Texture2D() const;
	virtual HRESULT Create(D3D11_TEXTURE2D_DESC* pDesc, D3D11_SUBRESOURCE_DATA* pInitData = NULL);
	virtual HRESULT GetRawDataInfo(unsigned long& nBufSize, unsigned long& nBufStride, UINT& nDepth, UINT& nChannel);
	virtual HRESULT GetRawData(void* pBuf);
	virtual HRESULT SetRawData(void* pBuf, unsigned long nImgBufSize, unsigned long nImgBufStride, UINT nDepth, UINT nChannel);

	virtual HRESULT SaveToFile(LPCWSTR path);
	virtual HRESULT LoadFromFile(LPCWSTR path, D3DX11_IMAGE_LOAD_INFO* pImageInfo = NULL);

	virtual HRESULT Resize(UINT width, UINT height);
	virtual HRESULT ResetFormat(DXGI_FORMAT fmt);


	virtual HRESULT GetFrameSize(UINT* width, UINT* height);
	// override CDXResource
	virtual BOOL IsKeyMutexShared();
	virtual HRESULT OpenShareHandle(HANDLE hResource);
	virtual ID3D11Resource* GetResource() const;
	virtual HRESULT GetDesc(D3D11_TEXTURE2D_DESC* pOutDesc);
	virtual HRESULT CopyFrom(CDXTexture2D* pCDXTexture);


	using CDXResource::GetShaderResourceView;
	using CDXResource::GetUnorderedAccessView;
	using CDXResource::GetRenderTargetView;
	virtual HRESULT GetShaderResourceView(DXGI_FORMAT fmt, UINT MostDetailedMip, UINT MipLevels, ID3D11ShaderResourceView** ppShaderResourceView);
	virtual HRESULT GetUnorderedAccessView(DXGI_FORMAT fmt, UINT MipSlice, ID3D11UnorderedAccessView** ppUnorderAccessView);
	virtual HRESULT GetRenderTargetView(DXGI_FORMAT fmt, UINT MipSlice, ID3D11RenderTargetView** ppRenderTargetView);


};
